﻿using System;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;


namespace ZoambieGaem {
    class Blood
    {
        public Vector2 worldPosition;
        public float destinationSize;
        public float size;
        public float angle;
        public float drawAngle;
        public Color color;
        public float transparency;
        public int centerX;
        public int centerY;
        public int type;
        public float speed;
        public Boolean stopped;

        public Blood(Master m, Vector2 worldPosition, int type, float angle) {
            stopped = false;
            this.angle = angle;
            this.type = type;
            this.speed = 10f;
            Random randNum = new Random();
            float temp = (float)randNum.NextDouble();
            if (temp < 0.4)
                temp = 0.4f;
            size = 1;
            destinationSize = 4f * (temp);
            randNum = new Random();
            temp = (float)randNum.NextDouble();
            temp = (temp * 360) - 180;
            this.drawAngle = temp;

            this.centerX = m.playerBloodTexture.Width / 2;
            this.centerY = m.playerBloodTexture.Height / 2;

            this.worldPosition = worldPosition;
            this.transparency = 255f;

            color = new Color(255,255,255,this.transparency);
	    }

        public void update(Master m) {

            Boolean disappeared = false;
            this.transparency -= 0.05f;

            if (this.transparency <= 1) {
                m.bloodList.Remove(this);
                disappeared = true;
            }

            if (!disappeared) {

                if (this.type == 1)
                    this.color = Color.FromNonPremultiplied(0, 200, 0, (int)this.transparency);
                if (this.type == 0)
                    this.color = Color.FromNonPremultiplied(200, 0, 0, (int)this.transparency);

                if (!this.stopped) {
                    nextPos();
                    this.speed -= 0.75f;

                    if (this.size < this.destinationSize)
                        this.size += this.destinationSize / 10;

                    if (this.speed <= 0.01) {
                        this.speed = 0;
                        stopped = true;
                    }

                    if (this.speed > 0.01)
                        this.drawAngle += this.speed / 25;
                }
            }
        }


        public void nextPos() {
            Vector2 nextPos = new Vector2(this.worldPosition.X + (float)(Math.Cos(this.angle) * this.speed),
                                          this.worldPosition.Y + (float)(Math.Sin(this.angle) * this.speed));
            this.worldPosition = nextPos;
        }

    }
}

